package com.zjkj.mp.controller.financeManage;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zjkj.mp.service.finance.FinanceItemService;
import com.zjkj.mp.utils.PaginatedResult;

/**
 * 
 * 财务明细控制器
 *
 * @author 陈晨
 * @history
 * <TABLE id="HistoryTable" border="1">
 * 	<TR><TD>时间</TD><TD>描述</TD><TD>作者</TD></TR>
 *	<TR><TD>2013-6-9</TD><TD>创建初始版本</TD><TD>陈晨</TD></TR>
 * </TABLE>
 */
@Controller
public class CWMXController {
    private int pageSize = 8;
    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-ddHHmmss");
	@Autowired
	FinanceItemService financeItemService;

	/******************************* 财务明细 
	 * @throws ParseException ***********************************/

	@RequestMapping("/financeDetailList.do")
	public String financeDetailList(HttpServletRequest req) throws ParseException{
		String pageNoStr = req.getParameter("pageNo");
		if(pageNoStr == null) pageNoStr = "1";
		
		String userName = req.getParameter("userName");
		String operateType = req.getParameter("operateType");		
		String beginDate = req.getParameter("beginDate");
		String endDate = req.getParameter("endDate");
		
		//分页得到财务明细
		Map<String,Object> params = new HashMap<String, Object>();
		if(!"".equals(userName)&&null!=userName)params.put("userName", userName);
		if(!"".equals(operateType)&&null!=operateType) params.put("operateType", operateType);
		if(!"".equals(endDate)&&null!=endDate)params.put("endDate", sdf.parse(endDate +"235959") );
		if(!"".equals(beginDate)&&null!=beginDate)params.put("beginDate", sdf.parse(beginDate +"000000"));
		
		PaginatedResult result = this.financeItemService.getList(Integer.parseInt(pageNoStr), pageSize,params);
		req.setAttribute("result", result);
		req.setAttribute("userName", userName);
		req.setAttribute("operateType", operateType);
		req.setAttribute("beginDate", beginDate);
		req.setAttribute("endDate", endDate);
		
		return "finance/financeMXInfo";
	} 
}
